<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    *{
        margin: 0;
        padding: 0;
        list-style: none;
    }
    #wrap{
        width: 1280px;
        height: 768px;
        position: relative;
        margin-left: 50px;
        margin-top: 50px;
        overflow: hidden;
    }
    ul{
        width: 5950px;
        height: 100%;
        position: absolute;
        
    }
    li{
        float: left;
        border:1px yellow solid; 
        position: relative;
    } 
    h3{
        color:rgba(0, 0, 0,.8);
    }
    .bigimg{
        display: none;
        position: absolute;
        width: 500px;
        height: 400px;
        border: 5px red solid;
        box-shadow: 0 0 20 #000;
        top:0;
        left: 0;
        z-index: 10;
    }
    </style>
</head>
<body>
   
    <div id="wrap">
            <h3>家庭滚动相册</h3>
            <ul>
                    <li><img src="images/1.jpg"><img src="images/a1.png" class="bigimg"></li>
                    <li><img src="images/2.jpg"><img src="images/a2.jpg" class="bigimg"></li>
                    <li><img src="images/3.jpg"><img src="images/a3.jpg" class="bigimg"></li>
                    <li><img src="images/4.jpg"><img src="images/a4.jpg" class="bigimg"></li>
                    <li><img src="images/5.jpg"><img src="images/a5.jpg" class="bigimg"></li>
                    <li><img src="images/6.jpg"><img src="images/a6.jpg" class="bigimg"></li>
                    <li><img src="images/7.jpg"><img src="images/a7.jpg" class="bigimg"></li>
                    <li><img src="images/8.jpg"><img src="images/a8.jpg" class="bigimg"></li>
                    <li><img src="images/9.jpg"><img src="images/a9.jpg" class="bigimg"></li>
                    <li><img src="images/10.jpg"><img src="images/a10.jpg" class="bigimg"></li>
                    <li><img src="images/1.jpg"><<img src="images/a1.png" class="bigimg"></li>
                    <li><img src="images/2.jpg"><img src="images/a2.jpg" class="bigimg"></li>
                    <li><img src="images/3.jpg"><img src="images/a3.jpg" class="bigimg"></li>
                    <li><img src="images/4.jpg"><img src="images/a4.jpg" class="bigimg"></li>
                    <li><img src="images/5.jpg"><img src="images/a5.jpg" class="bigimg"></li>
                    <li><img src="images/6.jpg"><img src="images/a6.jpg" class="bigimg"></li>
                    <li><img src="images/7.jpg"><img src="images/a7.jpg" class="bigimg"></li>
                    <li><img src="images/8.jpg"><img src="images/a8.jpg" class="bigimg"></li>
                    <li><img src="images/9.jpg"><img src="images/a9.jpg" class="bigimg"></li>
                    <li><img src="images/10.jpg"<img src="images/a10.jpg" class="bigimg"></li>
                </ul>
    </div>
   <script>
       (function(){
           var oul=document.querySelector("#wrap ul");
           var oli=document.querySelectorAll("#wrap ul li");
           var bigpic=document.getElementsByClassName("bigimg");
           var left=oul.offsetLeft;  //获取的为数字
           var width=oul.offsetWidth;//获取的为数字
           console.log(left,width);
           var speed=1;
           var timer;
           auto();
           function auto(){
               left-=speed;
               if(left<=-width/2){
                   left=0;
               }
               oul.style.left=left+"px";//需要加上PX
              timer=requestAnimationFrame(auto);
           }
           oul.onmouseenter=function(){
                cancelAnimationFrame(timer);
              }

            oul.onmouseout=function(){
                  auto();
                  }
               
            function getelementx(obj){
               var length=obj.offsetLeft;
               obj=obj.offsetParent;
               while(obj!=null){
                   length=length+obj.offsetLeft;
                   obj=obj.offsetParent;
               }
               return length;
           }
           function getelementy(obj){
               var length=obj.offsetTop;
               obj=obj.offsetParent;
               while(obj!=null){
                   length=length+obj.offsetTop;
                   obj=obj.offsetParent;
               }
               return length;
           }
           
           for(var i=0;i<oli.length;i++){
               oli[i].a=i;//自定义属性
               oli[i].onmousemove=function(e){
                cancelAnimationFrame(timer);
                   index=this.a;
                   var sreenX=e.clientX;
                   var sreenY=e.clientY;
                   var ex=getelementx(this);
                   var ey=getelementy(this);
                   _x=sreenX-ex;
                   _y=sreenY-ey;
                   bigpic[index].style.left=_x+"px";
                   bigpic[index].style.top=_y+"px";
                   bigpic[index].style.display="block";
               }
               oli[i].onmouseout=function(){
                bigpic[index].style.display="none";
               }
                 
           } 
               
        }   
        
       )()
      
          
   </script>
</body>
</html>